package com;

import java.text.DecimalFormat;
import java.util.Arrays;

public class Triangle {

	private double[] sides = new double[3];
	private DecimalFormat format = new DecimalFormat("0.0000000000000");
	private double area = 0.0;
	private double cosValue = 0.0;
	
	public Triangle(int[] points) {
		double side1 = new Double(Math.sqrt(Math.pow((points[0]-points[2]), 2)+Math.pow((points[1]-points[3]), 2))).doubleValue();
		double side2 = new Double(Math.sqrt(Math.pow((points[0]-points[4]), 2)+Math.pow((points[1]-points[5]), 2))).doubleValue();
		double side3 = new Double(Math.sqrt(Math.pow((points[2]-points[4]), 2)+Math.pow((points[3]-points[5]), 2))).doubleValue();
		sides[0] =side1;
		sides[1] =side2;
		sides[2] =side3;
		this.calculateArea();
		this.calculateBiggestAngel();
	}
	
	private void calculateArea() {
		double s = (sides[0] + sides[1] + sides[2])/2;
		this.area = Math.sqrt(s*(s-sides[0])*(s-sides[1])*(s-sides[2]));
	}
	
	public boolean isTrianle() {
		if (this.area > 0)
			return true;
		else
			return false;
	}
	
	private void calculateBiggestAngel() {
		Arrays.sort(sides);
		if(this.area > 0)
			cosValue = new Double(format.format((Math.pow(sides[0], 2)+Math.pow(sides[1], 2)-Math.pow(sides[2], 2))/(2*sides[0]*sides[1]))).doubleValue();
	}
	
	private String triangleCategoryByLength() {
		if(sides[0] == sides[1] || sides[0] == sides[2] || sides[1] == sides[2])
			return "isosceles";
		else
			return "scalene";
	}
	
	private String triangleCategoryByAngle() {
		if (cosValue > 0)
            return "acute";
        else if(cosValue < 0)
            return "obtuse";
        else
        	return "right";
	}
	
	public String getTrianlgeDescription() {
		if (this.isTrianle())
			return this.triangleCategoryByLength()+" "+ this.triangleCategoryByAngle()+" triangle";
		else
			return "not a triangle";
	}
}
